package com.wyj.server;

import com.wyj.classloader.MyWebAppLoader;
import com.wyj.classloader.WebAppFileProcessor;

import java.util.Map;

/**
 * TODO: 表示一个应用。一个host可以有多个。
 *
 * @author wuyijie
 * @date 2021/12/13 22:03
 */
public class Context{
    /**
     * web应用程序的url前缀
     * */
    private final String path;
    /**
     * web应用程序的路径
     * */
    private final String docBase;
    private final Map<String,Wrapper> wrapperMap;

    /**
     * 当前context的类加载器
     * */
    private final ClassLoader classLoader;


    public Context(String path, String docBase, Map<String, Wrapper> wrapperMap) {
        this.path = path;
        this.docBase = docBase;
        this.wrapperMap = wrapperMap;
        this.classLoader=new MyWebAppLoader(docBase);

        WebAppFileProcessor webAppFileProcessor = new WebAppFileProcessor(this.classLoader, this.docBase);
        webAppFileProcessor.process(this.wrapperMap);
    }

    @Override
    public String toString() {
        return "Context{" +
                "path='" + path + '\'' +
                ", docBase='" + docBase + '\'' +
                ", wrapperMap=" + wrapperMap +
                ", classLoader=" + classLoader +
                '}';
    }

    public String getPath() {
        return path;
    }

    public String getDocBase() {
        return docBase;
    }

    public Map<String, Wrapper> getWrapperMap() {
        return wrapperMap;
    }

    public ClassLoader getClassLoader() {
        return classLoader;
    }


}
